<template>
  <div v-if="visible">
    <el-dialog
      title="处理流程"
      :close-on-click-modal="false"
      width="70%"
      class="abow_dialog"
      :visible.sync="visible"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item v-for="item in dataList" :key="item.Id" :name="item.Instancenodeid">
          <template slot="title">
            <span style="display:block;width:100px">{{ item.Nodename }}</span> <i class="header-icon el-icon-info" />
            开始时间：{{ item.Begindate }}  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;完成时间： {{ item.Enddate }}
          </template>
          <LoadForm v-if="visible" ref="loadform" :vue-name="item.vueName" :src="item.Formkey" :data="item.Inputdata" />
        </el-collapse-item>
      </el-collapse>
    </el-dialog>
  </div>
</template>
<script>
import LoadForm from './loadform'
import { getInstanceNode } from '@/api/workflowprocess'
export default {
  components: {
    LoadForm
  },
  data() {
    return {
      visible: false,
      activeNames: [],
      dataForm: {
        Id: 0
      },
      dataList: []
    }
  },
  mounted() {
    this.visible = true
    console.log(1233)
  },
  methods: {
    init(id, instanceId) {
      this.visible = true
      this.activeNames = []
      this.$nextTick(() => {
        // const _option = this.$refs.loadform.$options
        const parameter = {
          'InstanceNodeId': id,
          'InstanceId': instanceId,
          'CandidateId': '1'
        }
        getInstanceNode(parameter).then((item) => {
          if (item.data) {
            item.data.forEach((data, index) => {
              if (index < 2) {
                this.activeNames.push(data.Instancenodeid)
              }
              var timestamp = (new Date()).valueOf()
              console.log('the method is init ' + timestamp)
              data.vueName = data.Processcode + '_' + data.Instancenodeid
              if (!data.Formkey) {
                data.Formkey = 'myworkflow/todo/components/approve'
              }
              if (data.Inputdata && typeof (data.Inputdata) === 'string') {
                data.Inputdata = JSON.parse(data.Inputdata)
              }
            })
          }
          this.dataList = item.data
        })
      })
    }
  }
}
</script>
